package de.mlp_distributed.mlp.math;

import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;

public class Factory {

	@Inject
	MatrixFactory matrixFactory;
	@Inject
	VectorFactory vectorFactory;

	private static Factory instance = null;

	public MatrixFactory getMatrixFactory() {
		return this.matrixFactory;
	}

	public VectorFactory getVectorFactory() {
		return this.vectorFactory;
	}

	public static Factory getInstance() {
		if (Factory.instance == null) {
			return Factory.getInstance(new FactoryModule());
		}
		return Factory.instance;
	}

	public static Factory getInstance(final AbstractModule module) {
		if (Factory.instance == null) {
			final Injector injector = Guice.createInjector(module);
			Factory.instance = injector.getInstance(Factory.class);
		}
		return Factory.instance;
	}

	private static class FactoryModule extends AbstractModule {

		@Override
		protected void configure() {
			// this.bind(VectorFactory.class).to(JBlasVectorFactory.class);
			// this.bind(MatrixFactory.class).to(JBlasMatrixFactory.class);
			this.bind(VectorFactory.class).to(MahoutVectorFactory.class);
			this.bind(MatrixFactory.class).to(MahoutMatrixFactory.class);
		}

	}

}
